# Helper methods defined here can be accessed in any controller or view in the application

module Myblog
  class System
    module LoginHelper
      def current_admin
        session[:admin]

      end

      def set_current_admin(admin)
        session[:admin] = admin
      end

      def destroy_current_admin
        session[:admin] = nil
      end

      def check_super_role
        if !current_admin
          @message = '请先登录'
          redirect url(:login, :index), :error => @message.html_safe+'<i class="close icon"></i>'.html_safe
        end
        if !current_admin.is_super
          @message = '您没有权限访问此模块'
          redirect url(:login, :index), :error => @message.html_safe+'<i class="close icon"></i>'.html_safe
        end
      end


      def check_seller_role
        if !current_admin
          @message = '请先登录'
          redirect url(:login, :index), :error => @message.html_safe+'<i class="close icon"></i>'.html_safe
        end
        if !current_admin.is_seller
          @message = '您没有权限访问此模块'
          redirect url(:login, :index), :error => @message.html_safe+'<i class="close icon"></i>'.html_safe
        end
      end


    end

    helpers LoginHelper
  end
end
